package com.qfedu.openplateform.manager.controller;

import com.github.pagehelper.PageInfo;
import com.qfedu.openplateform.manager.entity.AjaxMessage;
import com.qfedu.openplateform.manager.entity.Menu;
import com.qfedu.openplateform.manager.entity.Recharge;
import com.qfedu.openplateform.manager.entity.TableData;
import com.qfedu.openplateform.manager.service.RechargeService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * TODO
 *
 * @author DELL
 * @date 2021-10-27 21:43
 */
@RestController
@RequestMapping("/sys/recharge")
public class RechargeController {

    @Resource
    private RechargeService rechargeService;


    @RequestMapping("table")
    private TableData getRecharge(Recharge recharge,Integer page, Integer limit){

        PageInfo<Recharge> pageInfo = rechargeService.getRecharge(recharge, page, limit);

        return new TableData(pageInfo.getTotal(),pageInfo.getList());

    }


    @RequestMapping("del")
    public AjaxMessage deleteRecharge(int[] ids) {
        if (ids != null) {
            for (int id : ids) {

                rechargeService.deleteRechargeById(id);
                return new AjaxMessage(true, "删除成功");

            }
        }
        return new AjaxMessage(false,"未选择目标");

    }


    @RequestMapping("add")
    public AjaxMessage addRecharge(Recharge recharge){
        if (recharge!=null){
            rechargeService.addRecharge(recharge);
            return new AjaxMessage(true,"添加成功");
        }
        return new AjaxMessage(false,"添加失败");
    }


    @RequestMapping("update")
    public AjaxMessage updateRecharge(Recharge recharge){
        if (recharge!=null){
            rechargeService.updateRecharge(recharge);
            return new AjaxMessage(true,"修改成功");
        }
        return new AjaxMessage(false,"修改失败");
    }


    @RequestMapping( "/tree")
    public List<Recharge> tree() {
        return rechargeService.getRechargeTree();
    }
}
